package com.wings4.coresecurity

import com.wings4.security.User
import com.wings4.security.Authority
import com.wings4.security.Feature
import com.wings4.security.utils.EncryptionUtils

/**
 * Created with IntelliJ IDEA.
 * User: Administrator
 * Date: 2/20/14
 * Time: 8:50 PM
 * To change this template use File | Settings | File Templates.
 */
class AuthenticationToken {
    public Set<Authority> credential = null; //role
    public User principal; //user
    public Map<String,Collection<Set<Feature>>> grantedAuthority = null; //set of features

    private String username;
    private String password;

    public AuthenticationToken(username,password){
        authenticationToken(username,password);
    }

    def authenticationToken(userCode,password){
        principal = User.findByUserCodeAndPassword(userCode,new EncryptionUtils("wings4").encrypt(password));
        if(principal != null){
            credential = principal.authorities;
            grantedAuthority = new HashMap<String,Collection<Set<Feature>>>();
//            println "the credential features " + credential.features.size();
            grantedAuthority.put("features", credential.features);
        }
    }

}
